package com.knowledgegraph.web.controller.zhongyao;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledgegraph.common.annotation.Log;
import com.knowledgegraph.common.core.controller.BaseController;
import com.knowledgegraph.common.core.domain.AjaxResult;
import com.knowledgegraph.common.enums.BusinessType;
import com.knowledgegraph.zhongyao.domain.Introduce;
import com.knowledgegraph.zhongyao.service.IIntroduceService;
import com.knowledgegraph.common.utils.poi.ExcelUtil;
import com.knowledgegraph.common.core.page.TableDataInfo;

/**
 * 医案维护Controller
 * 
 * @author ruoyi
 * @date 2023-07-03
 */
@RestController
@RequestMapping("/zhongyao/introduce")
public class IntroduceController extends BaseController
{
    @Autowired
    private IIntroduceService introduceService;

    /**
     * 查询医案维护列表
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:introduce:list')")
    @GetMapping("/list")
    public TableDataInfo list(Introduce introduce)
    {
        startPage();
        List<Introduce> list = introduceService.selectIntroduceList(introduce);
        System.err.println(list.get(0).getUsername());
        return getDataTable(list);
    }

    /**
     * 导出医案维护列表
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:introduce:export')")
    @Log(title = "医案维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Introduce introduce)
    {
        List<Introduce> list = introduceService.selectIntroduceList(introduce);
        ExcelUtil<Introduce> util = new ExcelUtil<Introduce>(Introduce.class);
        util.exportExcel(response, list, "医案维护数据");
    }

    /**
     * 获取医案维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:introduce:query')")
    @GetMapping(value = "/{key}")
    public AjaxResult getInfo(@PathVariable("key") String key)
    {
        return AjaxResult.success(introduceService.selectIntroduceByKey(key));
    }

    /**
     * 新增医案维护
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:introduce:add')")
    @Log(title = "医案维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Introduce introduce)
    {
        System.err.println(introduce.getUsername());
        return toAjax(introduceService.insertIntroduce(introduce));
    }

    /**
     * 修改医案维护
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:introduce:edit')")
    @Log(title = "医案维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Introduce introduce)
    {
        return toAjax(introduceService.updateIntroduce(introduce));
    }

    /**
     * 删除医案维护
     */
    @PreAuthorize("@ss.hasPermi('zhongyao:introduce:remove')")
    @Log(title = "医案维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{keys}")
    public AjaxResult remove(@PathVariable String[] keys)
    {
        return toAjax(introduceService.deleteIntroduceByKeys(keys));
    }
}
